//
//  NewsListCell.m
//  News
//
//  Created by Han on 14-5-27.
//  Copyright (c) 2014年 UCoder. All rights reserved.
//

#import "NewsCell.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"
#import "Util.h"

@implementation NewsCell
@synthesize newsImg = _newsImg, newsTime = _newsTime, newsTitle = _newsTitle, favImg = _favImg, line = _line;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        //self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _newsImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"holder.png"]];
        [_newsImg setFrame:CGRectMake(10, 10, 75, 60)];
        [self addSubview:_newsImg];
        
        _newsTitle = [[UILabel alloc] initWithFrame:CGRectMake(93, 0, 220, 70)];
        //_newsTitle.backgroundColor = [UIColor darkGrayColor];
        _newsTitle.textAlignment = NSTextAlignmentLeft;
        _newsTitle.font = [UIFont systemFontOfSize:16.0];
        _newsTitle.textColor = [UIColor blackColor];
        _newsTitle.numberOfLines = 3;
        [_newsTitle setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
        [self addSubview:_newsTitle];
        
        _newsTime = [[UILabel alloc] initWithFrame:CGRectMake(220, 58, 93, 20)];
        _newsTime.textAlignment = NSTextAlignmentRight;
        _newsTime.font = [UIFont systemFontOfSize:13.0f];
        _newsTime.textColor = [UIColor lightGrayColor];
        //_newsTime.text = @"05-31 01:15";
        [_newsTime setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
        [self addSubview:_newsTime];
        
        //添加收藏
        _favImg = [[UIImageView alloc] initWithFrame:CGRectMake(320-35*0.5+0.5, 0, 35*0.5, 34*0.5)];
        [_favImg setContentMode:UIViewContentModeScaleAspectFit];
        [_favImg setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
        [_favImg setImage:[UIImage imageNamed:@"fav_sign"]];
        [self.contentView addSubview:_favImg];
        _favImg.hidden = YES;
        
        _line = [[UIView alloc]initWithFrame:CGRectMake(10, 80-0.5, 320, 0.5)];
        [self.contentView addSubview:_line];
        
        _line.backgroundColor = [UIColor lightGrayColor];
    }
    return self;
}

- (void)setNews:(News *)news {
    _newsTitle.text = news.title;
    
    _newsTime.text = [Util getDateFromTimestamp:news.time];
    //NSLog(@"%@", news.imgUrl);
    
    [_newsImg sd_setImageWithURL:[NSURL URLWithString:news.imgUrl]
                   placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    
    
    
    if (news.isFav) {
        _favImg.hidden = NO;
    } else {
        _favImg.hidden = YES;
    }

}


- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    if (selected) {
        // 点击时背景设置
        self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
        self.selectedBackgroundView.backgroundColor = [UIColor darkGrayColor];
    }
    
}


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"++++++++++");
}

@end
